package com.xtx.mapper;


import com.xtx.dto.PayDto;
import com.xtx.entity.Order;
import com.xtx.entity.OrderDetail;
import com.xtx.vo.PayOrderVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface PayMapper {
    
    @Insert("insert into order_detail(user_id,sku_id,goods_image,goods_name,order_id,count,price,attrs_text) values(#{userId},#{skuId},#{goodsImage},#{goodsName},#{orderId},#{count},#{price},#{attrsText})")
    void addOrderDetail(OrderDetail orderDetail);

    @Insert("insert into `order`(total_price,user_id,order_status,order_time,order_completed_time,order_id,pay_type,pay_channel,buyer_message,delivery_type,count) " +
            "values(#{totalPrice},#{userId},#{orderStatus},#{orderTime},#{orderCompletedTime},#{orderId},#{payType},#{payChannel},#{buyerMessage},#{deliveryType},#{count})")
    void addOrder(Order order);

    @Select("select order_id as `id`,total_price,order_time as createTime,pay_type,order_status,order_completed_time as payLatestTime,count" +
            " from `order` where order_id = #{orderId} and user_id = #{currentId}")
    PayOrderVo getPayOrder(String orderId, Long currentId);

    @Update("update `order` set order_status = 2, pay_type = #{payDto.payType} where order_id = #{payDto.orderId} and user_id = #{currentId}")
    void pay(PayDto payDto, Long currentId);

    @Update("update `order` set order_status = 5 where order_id = #{id} and user_id = #{currentId}")
    void cancelOrder(String id, Long currentId);
}
